//
//  SaleFinishCell.m
//  PigMarket
//
//  Created by 张敬 on 2019/8/21.
//  Copyright © 2019年 pigmarket.oc. All rights reserved.
//

#import "SaleFinishCell.h"

@implementation SaleFinishCell

#pragma mark - lifecycle methods

- (void)setupUI{
    
    self.backgroundColor = KWhiteColor;
    
    [self.contentView addSubview:self.pigTypeTipLab];
    [self.contentView addSubview:self.pigTypeNOLab];
    [self.contentView addSubview:self.pigTypePriceLab];
    [self.contentView addSubview:self.pigTypeWeightLab];
    [self.contentView addSubview:self.pigTypePriceSignalLab];

    
    [self.contentView addSubview:self.tipLab];
    [self.contentView addSubview:self.buyTipLab];
    [self.contentView addSubview:self.locationLab];
    [self.contentView addSubview:self.nicknameLab];
    [self.contentView addSubview:self.shopIcon];
    [self.contentView addSubview:self.ageLab];
    [self.contentView addSubview:self.timeLab];

    
}

- (void)setupLayout
{
    
    [self.pigTypeTipLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(13);
        make.top.mas_equalTo(15);
        make.width.mas_equalTo(80);
        make.height.mas_equalTo(22);
    }];
    
    [self.pigTypeNOLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.pigTypeTipLab.mas_right).mas_offset(4);
        make.top.mas_equalTo(15);
        make.right.mas_equalTo(-30);
        make.height.mas_equalTo(20);
    }];
    
    [self.pigTypePriceLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(24);
        make.right.mas_equalTo(-15);
        make.width.mas_equalTo(100);
        make.height.mas_equalTo(20);
    }];
    
    
    [self.pigTypeWeightLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(13);
        make.top.mas_equalTo(self.pigTypeTipLab.mas_bottom).mas_offset(7);
        make.width.mas_equalTo(66);
        make.height.mas_equalTo(16);
    }];

    
    [self.pigTypePriceSignalLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.pigTypeWeightLab.mas_right).mas_offset(5);
        make.top.mas_equalTo(self.pigTypeWeightLab.mas_top);
        make.width.mas_equalTo(89);
        make.height.mas_equalTo(16);
    }];
    
    [self.tipLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-15);
        make.top.mas_equalTo(self.pigTypePriceLab.mas_bottom).offset(5);
        make.width.mas_equalTo(32);
        make.height.mas_equalTo(13);
    }];
    
    CAShapeLayer *line = [CAShapeLayer layer];
    line.fillColor = UIColorFromRGB(0xF9F9F9).CGColor;
    UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(15, 73, KScreenWidth -15, 1)];
    line.path = path.CGPath;
    [self.contentView.layer addSublayer:line];
    
    [self.buyTipLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(self.pigTypeWeightLab.mas_bottom).offset(25);
        make.width.mas_equalTo(100);
        make.height.mas_equalTo(20);
    }];

    [self.timeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(self.buyTipLab.mas_bottom).offset(5);
        make.width.mas_equalTo(200);
        make.height.mas_equalTo(18);
    }];

    [self.shopIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-15);
        make.top.mas_equalTo(89);
        make.width.mas_equalTo(42);
        make.height.mas_equalTo(42);
    }];
    
    [self.nicknameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-69);
        make.top.mas_equalTo(91);
        make.width.mas_equalTo(200);
        make.height.mas_equalTo(20);
    }];

    
    [self.ageLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-69);
        make.top.mas_equalTo(self.nicknameLab.mas_bottom).offset(3);
        make.width.mas_equalTo(200);
        make.height.mas_equalTo(17);
    }];
    
    [self.locationLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(36);
        make.top.mas_equalTo(self.buyTipLab.mas_bottom).offset(5);
        make.right.mas_equalTo(-15);
        make.height.mas_equalTo(35);
    }];
    
}



#pragma mark - setter methods

- (void)setType:(SaleFinishCellType)type
{
    switch (type) {
        case SaleFinishCellType_Time:
            {
                _timeLab.hidden = NO;
                _locationLab.hidden = YES;
                _shopIcon.hidden = NO;
                _ageLab.hidden = NO;
                _nicknameLab.hidden = NO;

            }
            break;
            
        default:
            {
                _timeLab.hidden = YES;
                _locationLab.hidden = NO;
                _shopIcon.hidden = YES;
                _ageLab.hidden = YES;
                _nicknameLab.hidden = YES;
            }
            break;
    }
}

- (void)setItem:(ShopSaleDetailItem *)item{
    
    self.pigTypeTipLab.text = @"五花肉";
    self.pigTypeNOLab.text = @"HT-02";
    self.pigTypeWeightLab.text = [NSString stringWithFormat:@"重量%@kg", item.weight];
    self.pigTypePriceSignalLab.text = [NSString stringWithFormat:@"单价%@元/500g", item.unitPrice]; 
    self.pigTypePriceLab.text = @"¥216";

}

#pragma mark - getter methods


- (UILabel *)pigTypeTipLab{
    
    if (! _pigTypeTipLab){
        _pigTypeTipLab = [UILabel makeLabelWithText:@"" textColor:mMainColor font:mFont(12) textAliment:1];
        _pigTypeTipLab.backgroundColor = UIColorFromRGB(0xE9F9F0);
        [self addShadowAndCircleCorner:_pigTypeTipLab.layer corner:3];
    }
    return _pigTypeTipLab;
}


- (UILabel *)pigTypeNOLab{
    
    if (!_pigTypeNOLab){
        _pigTypeNOLab = [UILabel makeLabelWithText:@"" textColor:UIColorFromRGB(0x333333) font:mFont(15) textAliment:0];
    }
    return _pigTypeNOLab;
}


- (UILabel *)pigTypePriceLab{
    
    if (!_pigTypePriceLab){
        _pigTypePriceLab = [UILabel makeLabelWithText:@"" textColor:UIColorFromRGB(0x333333) font:mMediumFont(17) textAliment:2];
    }
    return _pigTypePriceLab;
}


- (UILabel *)pigTypeWeightLab {
    
    if (!_pigTypeWeightLab){
        _pigTypeWeightLab = [UILabel makeLabelWithText:@"" textColor:UIColorFromRGB(0x9C9C9C) font:mFont(10) textAliment:1];
        _pigTypeWeightLab.backgroundColor = UIColorFromRGB(0xF2F4F7);
        [self addShadowAndCircleCorner:_pigTypeWeightLab.layer corner:9];
    }
    return _pigTypeWeightLab;
}


- (UILabel *)pigTypePriceSignalLab{
    
    if (!_pigTypePriceSignalLab){
        _pigTypePriceSignalLab = [UILabel makeLabelWithText:@"" textColor:UIColorFromRGB(0x9C9C9C) font:mFont(10) textAliment:1];
        _pigTypePriceSignalLab.backgroundColor = UIColorFromRGB(0xF2F4F7);
        [self addShadowAndCircleCorner:_pigTypePriceSignalLab.layer corner:9];
    }
    return _pigTypePriceSignalLab;
}


- (UILabel *)tipLab{
    
    if (!_tipLab){
        _tipLab = [UILabel makeLabelWithText:@"赠送" textColor:KWhiteColor font:mMediumFont(8) textAliment:1];
//        UIImage *image = [UIImage imageNamed:@"meat_shop_sales_blank"];
//        
//        _tipLab.layer.contents = (__bridge id)image.CGImage;
        _tipLab.backgroundColor = KRedColor;
    }
    return _tipLab;
}

- (UILabel *)ageLab{
    
    if (!_ageLab){
        _ageLab = [UILabel makeLabelWithText:@"年龄：18" textColor:UIColorFromRGB(0xB2B2B2) font:mFont(12) textAliment:2];
    }
    return _ageLab;
}

- (UILabel *)buyTipLab{
    
    if (!_buyTipLab){
        _buyTipLab = [UILabel makeLabelWithText:@"购买人" textColor:UIColorFromRGB(0xB2B2B2) font:mFont(14) textAliment:0];
    }
    return _buyTipLab;
}

- (UILabel *)timeLab{
    
    if (!_timeLab){
        _timeLab = [UILabel makeLabelWithText:@"购买时间：" textColor:UIColorFromRGB(0xB2B2B2) font:mFont(13) textAliment:0];
    }
    return _timeLab;
}

- (UILabel *)locationLab{
    
    if (!_locationLab){
        _locationLab = [UILabel makeLabelWithText:@"地址：天津市武清开发区创业总部基地B座15号楼1208室、1205室" textColor:UIColorFromRGB(0x666666) font:mFont(12) textAliment:0];
        _locationLab.numberOfLines = 0;
        
    }
    return _locationLab;
}

- (UILabel *)nicknameLab{
    
    if (!_nicknameLab){
        _nicknameLab = [UILabel makeLabelWithText:@"呆萌小猪宝" textColor:UIColorFromRGB(0x343434) font:mFont(14) textAliment:2];
    }
    return _nicknameLab;
}


- (UIImageView *)shopIcon{
    
    if (!_shopIcon) {
        _shopIcon = [UIImageView new];
        _shopIcon.backgroundColor = KRedColor;
        
        [self addShadowAndCircleCorner:_shopIcon.layer corner:21];
    }
    return _shopIcon;
}


@end
